<template>
	<view>
		<view class="page-ov">
			<view class="" v-if="wxSet.categ_style != 2">
				<view class="list-two-w">
					<view class="list-two-list">
						<view class="list-name">
							虚怀若谷
						</view>
						<view class="list-name-slug">
							兮其若朴，旷兮其若谷
						</view>
					</view>
					<view class="list-two-img">
						<image class="fengrui-img" src="../../static/index/333.svg" mode="aspectFill"></image>
					</view>
				</view>

				<!-- 专题滑动区域 -->
				<view class="swiper-list">
					<scroll-view class="scroll-view_H" scroll-x="true" show-scrollbar="false">
						<block v-for="(cate ,index) in categoryList" :key="index">
							<view class="swiperzhuanti"  v-if="cate.xs_top == '1'"
								@tap="goArticleList(cate.id)">
								<view class="scroll-h-name">
									<view class="scroll-ruan">
										<image class="fengrui-img" src="../../static/down/ruan.svg" mode="aspectFit">
										</image>
									</view>
									{{ cate.name }}
								</view>
								<view class="list-name-slug">
									{{ cate.description }}
								</view>
								<view class="list-name-slug">
									数量：{{ cate.count }}
								</view>
								<view class="scroll-zhuan-img">
									<image class="fengrui-img" style="Opacity:0.9" :src="cate.cation_img"
										mode="aspectFit"></image>
								</view>
							</view>
						</block>
					</scroll-view>
				</view>

				<view class="subject-view">
					<view class="subject-h">
						专题分类
					</view>
					<view class="subject-list-v">
						<view class="subject-list"  v-for="(cate ,index) in categoryList"
							:key="index" @tap="goArticleList(cate.id)">
							<view class="subject-list-icon">
								<image class="fengrui-img" v-if="cate.cation_img != ''" :src="cate.cation_img"
									mode="aspectFit"></image>
								<image class="fengrui-img" v-else src="../../static/my/poster.svg" mode="aspectFit">
								</image>
							</view>
							<view class="subject-list-name">
								{{ cate.name }}
							</view>
						</view>
					</view>
				</view>

			</view>

			<!-- 二级分类 -->
			<block v-if="wxSet.categ_style == 2">
				<view class="paren-img" style="height: 300rpx;">
					<image class="fengrui-img" src="../../static/index/category.svg" mode="aspectFill"></image>
				</view>

				<view class="scroll-flex">
					<scroll-view scroll-y="true" class="left-muen" :style="{height:(viewHeight - 170) + 'px',}">
						<block v-for="(cate ,index) in lefList" :key="index">
							<view :class="tapIndenx === index ? 'left_view_citve':'left_view'" @tap="tapLeft(index)">
								{{cate.name}}
							</view>
						</block>
					</scroll-view>
					<scroll-view scroll-y="true" :style="{height:(viewHeight - 170) + 'px',}">
						<view class="right-view">
							<block v-for="(item,index) in reghtList" :key="index">
								<view class="right-list" @tap="goArticleList(item.id)">
									<view class="right-list-img">
										<image class="fengrui-img" :src="item.cation_img" mode="widthFix"></image>
									</view>
									<view class="right-list-name">
										{{item.name}}
									</view>
								</view>
							</block>
						</view>
					</scroll-view>
				</view>
			</block>
		</view>

		<!-- #ifdef MP-WEIXIN -->
		<!-- 关注微信公众号 -->
		<view class="account-view" v-if="wxSet.public_follow != '' && wxSet.categ_style != 2">
			<view class="account-flex">
				<!-- <view class="account-img">
					<image class="fengrui-img" :src="wxSet.public_logo" mode=""></image>
				</view> -->
				<view class="account-aout">
					<view class="account-name">
						{{ wxSet.public_name }}
					</view>
				</view>
			</view>
			<view class="">
				<button hover-class="fengrui-blue-btn-lo-hover" class="account-btn" @tap="accountTap()">关注</button>
			</view>
		</view>
		<!-- #endif -->

		<!-- 全屏加载 -->
		<cover-bulr-bg v-if="coverBulr"></cover-bulr-bg>

		<!-- 占位符 -->
		<view style="height: 100rpx;"> </view>
	</view>
</template>

<script>
	// 获取应用实例
	const app = getApp()
	import * as API from "../../utils/api";
	export default {
		data() {
			return {
				// 分类数据
				categoryList: [],
				tapIndenx: 0,
				indexID: '',
				lefList: [],
				reghtList: [],

				// 分类图片样式
				list_style: 2,

				// 页面高度
				viewHeight: '',
				// 基本配置
				wxSet: [],
				// 全屏加载
				coverBulr: true,
				// 页数
				page: 1,

			}
		},
		onLoad() {
			if (app.globalData.wxSet == '') {
				//（解决异步）
				app.on('wxSet', this.changeToken.bind(this));
			} else {
				this.wxSet = app.globalData.wxSet;
				// 分类数据
				this.category();
			}

			// 微信分享盆友圈
			//#ifdef MP-WEIXIN
			wx.showShareMenu({
				withShareTicket: true,
				menus: ['shareAppMessage', 'shareTimeline']
			})
			//#endif
		},

		// 下拉刷新
		onPullDownRefresh() {
			this.category();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},

		// 分享好友配置
		onShareAppMessage(res) {
			if (res.from === 'button') { // 来自页面内分享按钮
				console.log(res.target)
			}
			return {
				title: this.wxSet.share_title,
				imageUrl: this.wxSet.share_title_url,
				path: 'pages/category/category',
			}
		},
		// 监听触底----上啦刷新
		onReachBottom() {
			this.page = this.page + 1;
			if (this.wxSet.categ_style == '1') {
				this.categoryPge();
			} else {
				this.tapRight();
			}
		},

		methods: {
			//（解决异步）
			changeToken() {
				this.wxSet = app.globalData.wxSet;
				// 分类数据
				this.category();
			},

			// 分类数据
			category() {
				if (this.wxSet.categ_style == '2') {
					// 二级分类
					API.getCategoryParent([this.wxSet.categ_filter], [1]).then((res) => {
						this.lefList = res.data;
						this.tapLeft(0);
						// console.log('分类数据', res.data)
						// 获取界面高度
						this.viewHeight = uni.getSystemInfoSync().windowHeight;
					})
				} else {
					// 一级
					API.getCategory([this.wxSet.categ_filter], [1]).then((res) => {
						this.categoryList = res.data;
						// console.log('分类数据', res.data)
					})
				}

				setTimeout(() => {
					this.coverBulr = false;
				}, 600)
			},

			// 上拉加载
			categoryPge() {
				API.getCategory([this.wxSet.categ_filter], [this.page]).then((res) => {
					this.categoryList = this.categoryList.concat(res.data);
					// console.log('上拉加载分类数据', res.data)
				})
			},

			// 点击跳转
			goArticleList(e) {
				uni.navigateTo({
					url: '../list/list?catepos=' + e,
				})
			},

			// 关注微信公众号
			accountTap() {
				uni.navigateTo({
					url: '../follow/follow',
				})
			},

			// 左边点击
			tapLeft(e) {
				this.tapIndenx = e;
				this.indexID = this.lefList[e].id;
				this.tapRight();
				this.page = 1;
				this.reghtList = [];
			},
			// 右侧数据
			tapRight() {
				API.getCategoryParentID([this.wxSet.categ_filter], [this.page], [this.indexID]).then((res) => {
					this.reghtList = this.reghtList.concat(res.data);
					// console.log('上拉加载分类数据', res.data)
				})
			},
		}

	}
</script>

<style>
	/* 子分类 */
	.right-list-name {
		text-align: center;
		margin-top: 10rpx;
		font-size: 28rpx;
	}

	.right-list {
		width: 31%;
		flex-shrink: 0;
		margin: 30rpx 0rpx;
	}

	.right-list-img {
		height: 120rpx;
		width: 120rpx;
		overflow: hidden;
		border-radius: 10rpx;
		display: block;
		margin: auto;
	}

	.right-view {
		display: flex;
		justify-content: flex-start;
		align-items: center;
		flex-wrap: wrap;
	}

	.scroll-flex {
		display: flex;
	}

	.paren-img {
		height: 300rpx;
		margin: 30rpx;
		border-radius: 40rpx;
		overflow: hidden;
	}

	/* 左侧菜单 */
	.left-muen {
		width: 260rpx;
		height: 100%;
		border-radius: 40rpx;
		overflow: hidden;
		margin-left: 30rpx;
		background-color: #fff;
	}

	.left_view {
		background-color: #ffffff;
		height: 120rpx;
		flex-shrink: 0;
		width: 100%;
		font-size: 28rpx;
		text-align: center;
		line-height: 120rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
	}

	.left_view_citve {
		background-color: #FFFFFF;
		height: 120rpx;
		width: 100%;
		flex-shrink: 0;
		font-size: 28rpx;
		text-align: center;
		line-height: 120rpx;
		position: relative;
		color: #007AFF;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
	}

	.left_view_citve:before {
		content: ' ';
		height: 50rpx;
		width: 10rpx;
		border-radius: 0rpx 100rpx 100rpx 0rpx;
		background-color: #007AFF;
		position: absolute;
		left: 0;
		top: 50%;
		transform: translateY(-50%);
		height: 60rpx;
	}

	/* 模式1 */
	.scroll-h-name {
		display: flex;
		justify-content: flex-start;
		align-items: center;
		font-weight: 600;
	}

	.scroll-zhuan-img {
		width: 80rpx;
		height: 80rpx;
		position: absolute;
		right: 0rpx;
		bottom: 0rpx;
	}

	.swiperzhuanti:last-child {
		margin-right: 30rpx;
	}

	.scroll-ruan {
		height: 30rpx;
		width: 30rpx;
		border-radius: 200rpx;
		margin-right: 10rpx;
		margin-bottom: 6rpx;
	}

	.swiperzhuanti {
		width: 320rpx;
		padding: 30rpx;
		height: 140rpx;
		background-color: #FFFFFF;
		border-radius: 40rpx;
		display: inline-block;
		margin-left: 30rpx;
		position: relative;
	}

	.swiper-list {
		white-space: nowrap;
	}

	/* 关注微信公众号 */
	.account-aout {
		margin-left: 30rpx;
	}

	.account-btn {
		height: 60rpx;
		background-color: #007AFF;
		border-radius: 200rpx;
		font-size: 24rpx;
		width: 150rpx;
		color: #FFFFFF;
		flex-shrink: 0;
		margin-right: 0rpx;
	}

	.account-describe {
		font-size: 20rpx;
		color: #7c7c7c;
	}

	.account-img {
		height: 80rpx;
		width: 80rpx;
		border-radius: 200rpx;
		overflow: hidden;
	}

	.account-flex {
		display: flex;
	}

	.account-view {
		background-color: #FFFFFF;
		border-radius: 40rpx;
		height: 120rpx;
		margin: 30rpx 30rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 18rpx;
	}

	/* 星尘大图模式 */
	.list-big-cout {
		position: absolute;
		right: 30rpx;
		bottom: 30rpx;
		color: #807C7C;
		font-size: 20rpx;
	}

	.list-big-slug {
		font-size: 20rpx;
		color: #807C7C;
		margin: -20rpx 30rpx 30rpx 30rpx;

	}

	.list-big-h {
		font-size: 34rpx;
		margin: 30rpx;
	}

	.list-big-img {
		height: 260rpx;
		overflow: hidden;
		background-color: #000000;
		border-radius: 40rpx;
	}

	.list-big-view {
		position: relative;
		background-color: #FFFFFF;
		border-radius: 40rpx;
		overflow: hidden;
		margin: 50rpx 30rpx;
	}

	/* 文章列表双排小图 */
	.subject-h {
		margin: 30rpx;
		font-size: 32rpx;
		font-weight: 600;
	}

	.subject-list-name {
		text-align: center;
		margin-top: 18rpx;
		font-size: 28rpx;
	}

	.subject-list-v {
		display: flex;
		/* justify-content: start; */
		align-items: center;
		flex-flow: wrap;
	}

	.subject-list {
		margin: 30rpx 0rpx;
		width: 228rpx;
		flex-shrink: 0;
	}

	.subject-list-icon {
		height: 80rpx;
		width: 80rpx;
		margin: auto;
		border-radius: 10rpx;

	}

	.subject-view {
		background-color: #FFFFFF;
		border-radius: 40rpx;
		margin: 30rpx 30rpx;
		overflow: hidden;
	}

	.list-two-abstract {
		color: #ADADAD;
		font-size: 24rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		margin-top: 14rpx;
	}

	.list-two-title {
		font-size: 30rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		margin-top: 26rpx;
	}

	.list-two-img {
		width: 250rpx;
		height: 250rpx;
		border-radius: 40rpx;
		/* overflow: hidden; */
		margin: -50rpx 50rpx 0rpx 50rpx;
		flex-shrink: 0;
	}

	.list-two-img-all {
		width: 260rpx;
		height: 130rpx;
		border-radius: 40rpx;
		overflow: hidden;
		flex-shrink: 0;
		margin-right: 50rpx;
	}

	.list-two-list {
		margin: 0rpx 50rpx;

	}

	.list-name {
		font-size: 38rpx;
		margin-bottom: 6rpx;

	}

	.list-name-slug {
		font-size: 20rpx;
		color: #807C7C;
		margin-bottom: 6rpx;

		margin-top: 16rpx;
	}

	.list-two-w {
		margin: 30rpx 30rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		background-color: #FFFFFF;
		border-radius: 40rpx;
		/* overflow: hidden; */
		height: 220rpx;
	}

	/* 热评 */
	.review {
		background-color: #f9f9f9;
		padding: 32rpx;
		margin: 34rpx 30rpx;
		border-radius: 10rpx;
		color: #807C7C;
		font-size: 24rpx;
	}

	.status-ma40 {
		margin: 30rpx;
	}

	.fengrui-img {
		height: 100%;
		width: 100%;
	}

	.page-ov {
		overflow: hidden;
	}

	page {
		background-color: #F7F7F7;
	}

	::-webkit-scrollbar {
		width: 0;
		height: 0;
		color: transparent;
	}

	/* 暗黑模式下应用的样式 */
	@media (prefers-color-scheme: dark) {

		page,
		.data-login-flex {
			background: #161616;
		}

		.left-muen,
		.left_view,
		.left_view_citve,
		.account-view,
		.subject-view,
		.swiperzhuanti,
		.list-two-w,
		.list-big-view {
			background: #202020;
		}
	}
</style>